<?php
class node_m extends m{
  function __construct()
  {
    parent::__construct();
    $this->table = 'node';
    $this->key = 'uuid';
    $this->fields = array('sid','uuid','name','type','upid','title','content','ext','meta','tags','order','create_date','update_date');
  }

  function n($name)
  {
    $r = $this->get(" and `name`='$name'");
    return $r[0];
  }
    // 向数据库插入数组格式数据
  function replace( $elem = FALSE)
  {
    $query_list = array();
    if(!$elem)$elem = $_POST;
    foreach($this->fields as $f) {
      if(isset($elem[$f])){
        $elem[$f] = $this->db->escape(is_array($elem[$f])?_encode($elem[$f]):$elem[$f]);
        $query_list[] = "`$f` ";
        $query_list1[] = "'$elem[$f]'";
      }
    }
    $query = "replace into `$this->table` (".implode(',',$query_list).") values (".implode(',',$query_list1).")  ";
    $this->db->query($query);
    if(in_array('uuid',$this->fields)) return $elem['uuid'];
    return $this->db->insert_id();
  }
}
